<?php
namespace App\Http\Requests\Trade\Demand;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use App\Models\Trade\Demand\DemandModel;

class ListRequest extends FormRequest
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'page' => 'nullable|integer|between:1,10000',
            'page_size' => 'nullable|integer|between:1,100',
            'order' => [
                'nullable',
                Rule::in(DemandModel::getOrderList())
            ],
            'verify' => [
                'nullable',
                Rule::in(DemandModel::getVerifyList())
            ],
            'kind_id' => 'nullable|integer|min:1',
            'province' => 'nullable|integer|min:1',
            'city' => 'nullable|integer|min:1',
            'keyword' => 'nullable|string|max:20'
        ];
    }

    /**
     * 获取已定义的验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'order.in' => ':attribute 必须在[' . implode(',', DemandModel::getOrderList()) . ']中',
            'verify.in' => ':attribute 必须在[' . implode(',', DemandModel::getVerifyList()) . ']中'
        ];
    }
}
